home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / opt0.4.lcm / bin / eci-doctor.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-02-26  |  14.3 KB  |  515 lines

  1. #!/bin/sh
  2.  
  3. # Author: Benoit PAPILLAULT <benoit.papillault@free.fr>
  4. # Creation: 01/02/2002
  5. # Licence: GPL
  6.  
  7. # 02/02/2002: added the permission check for check-hdlc & check-hdlc-bug
  8. # 07/02/2002: added check on the pppd output. added the CVS Id.
  9.  
  10. # CVS $Id: eci-doctor.sh,v 1.28 2003/02/03 15:15:27 wwp Exp $
  11. # Tag $Name: release-0-8 $
  12.  
  13. # 16/02/2002 Benoit PAPILLAULT
  14. #   Check for an existing pppd and display its version
  15.  
  16. # 26/02/2002 Benoit PAPILLAULT
  17. #   Added the 'nopersist' flag for diagnostic purpose.
  18.  
  19. # <CONFIG>
  20. ETC_DIR="/etc"
  21. CONF_DIR="/etc/eciadsl"
  22. BIN_DIR="/usr/local/bin"
  23. PPPD_DIR="/etc/ppp"
  24. VERSION=""
  25. # </CONFIG>
  26.  
  27. if [ "$1" == "--version" -o "$1" == "-v" ]; then
  28.     echo "$VERSION"
  29.     exit 0
  30. fi
  31.  
  32. # cd to the directory where the 'doctor' is.
  33. cd `dirname $0`
  34.  
  35. PATH=/bin:/sbin:/usr/bin:/usr/sbin
  36.  
  37. if [ `id -u` -ne 0 ]; then
  38.     echo "You need to be root (type su)" ;
  39.     exit -1;
  40. fi
  41.  
  42. # display the kernel version
  43. echo "You are using linux kernel version `uname -r`"
  44.  
  45. # note the size in lines of /var/log/messages
  46. line=`wc -l /var/log/messages | awk '{print $1}'`
  47.  
  48. function fatal () {
  49.     tail +$line /var/log/messages > /tmp/msg.log
  50. # check for "usb-uhci.c: ENXIO 80000380, flags 0, urb c7f401c0, burb c6469140"
  51.     grep 'usb-uhci.c: ENXIO' /tmp/msg.log
  52.  
  53. # check for "usb-uhci.c: interrupt, status 29, frame# 956"
  54.     grep 'usb-uhci.c: interrupt' /tmp/msg.log
  55.  
  56. # check for "usb_control/bulk_msg: timeout"
  57.     grep 'usb_control/bulk_msg' /tmp/msg.log
  58.  
  59. # check for "usb-uhci.c: Host controller halted, trying to restart"
  60.     grep 'usb-uhci.c: Host controller halted' /tmp/msg.log
  61.  
  62. # check for "usb-uhci.c: process_transfer: fixed toggle"
  63.     grep 'usb-uhci.c: process_transfer' /tmp/msg.log
  64.  
  65. # check for "usb-uhci.c: iso_find_start: gap in seamless isochronous scheduling"
  66.     grep 'usb-uhci.c: iso_find_start' /tmp/msg.log
  67.     rm /tmp/msg.log
  68.     exit -1;
  69. }
  70.  
  71. if [ ! -d /proc/bus/usb ]; then
  72.     echo "Support for USB is missing... trying to load" ;
  73.     modprobe usbcore
  74.     sleep 1
  75.     if [ ! -d /proc/bus/usb ]; then
  76.         echo "Support for USB: failed to load" ;
  77.         fatal;
  78.     else
  79.         echo "Support for USB is OK" ;
  80.     fi
  81. else
  82.     echo "Support for USB is OK" ;
  83. fi
  84.  
  85. # mount usbdevfs is this is not the case
  86. if [ ! -f /proc/bus/usb/devices ]; then
  87.     echo "Preliminary USB device filesystem is missing... trying to mount" ;
  88.     mount -t usbdevfs none /proc/bus/usb
  89.     sleep 1
  90.     if [ ! -f /proc/bus/usb/devices ]; then
  91.         echo "Preliminary USB device filesystem: failed to load" ;
  92.         fatal ;
  93.     else
  94.         echo "Preliminary USB device filesystem is OK" ;
  95.     fi
  96. else
  97.     echo "Preliminary USB device filesystem is OK" ;
  98. fi
  99.  
  100. # check for the dabusb module
  101. lsmod | grep "^dabusb" > /dev/null
  102. if [ $? -eq 0 ]; then
  103.     echo "dabusb module is loaded: trying to unload!" ;
  104.     modprobe -r dabusb
  105.     sleep 1
  106.     lsmod | grep "^dabusb" > /dev/null
  107.     if [ $? -eq 0 ]; then
  108.         echo "dabusb module cannot be unloaded, verify if it is busy";
  109.         fatal;
  110.     else
  111.         echo "dabusb module unloaded: OK";
  112.     fi
  113. else
  114.     echo "dabusb module is not loaded: OK";
  115. fi
  116.  
  117. # check for the ehci-hcd module
  118. lsmod | grep "^ehci-hcd" > /dev/null
  119. if [ $? -eq 0 ]; then
  120.     echo "ehci-hcd module is loaded: trying to unload!" ;
  121.     modprobe -r ehci-hcd
  122.     sleep 1
  123.     lsmod | grep "^ehci-hcd" > /dev/null
  124.     if [ $? -eq 0 ]; then
  125.         echo "ehci-hcd module cannot be unloaded, verify if it is busy";
  126.         fatal;
  127.     else
  128.         echo "ehci-hcd module unloaded: OK";
  129.     fi
  130. else
  131.     echo "ehci-hcd module is not loaded: OK";
  132. fi
  133.  
  134. # try to locate UHCI controller
  135. uhci=0
  136. # directly check for the UHCI driver (avoid to use /proc/pci if there is none)
  137. grep "^S:  Product=USB UHCI Root Hub" /proc/bus/usb/devices > /dev/null
  138. if [ $? -ne 0 ]; then
  139.     if [ -f /proc/pci ]; then
  140.         grep -A 4 USB /proc/pci | grep I/O > /dev/null
  141.         if [ $? -eq 0 ]; then
  142.         # ok, we have a UHCI controller, check if the linux driver is loaded
  143.             grep "^S:  Product=USB UHCI Root Hub" /proc/bus/usb/devices > /dev/null
  144.             if [ $? -ne 0 ]; then
  145.                 echo "UHCI support is missing... trying to load" ;
  146.                 modprobe usb-uhci
  147.                 modprobe uhci
  148.                 sleep 2
  149.                 grep "^S:  Product=USB UHCI Root Hub" /proc/bus/usb/devices > /dev/null
  150.                 if [ $? -ne 0 ]; then
  151.                     echo "UHCI support: failed to load" ;
  152.                 else
  153.                     echo "UHCI support is OK" ;
  154.                     uhci=1 ;
  155.                 fi
  156.             else
  157.                 echo "UHCI support is OK" ;
  158.                 uhci=1 ;
  159.             fi
  160.         fi
  161.     else
  162.         echo "You don't have /proc/pci. I cannot check for a UHCI controller";
  163.     fi
  164. else
  165.     echo "UHCI support is OK" ;
  166.     uhci=1;
  167. fi
  168.  
  169. # try to locate OHCI controller
  170. ohci=0
  171. grep "^S:  Product=USB OHCI Root Hub" /proc/bus/usb/devices > /dev/null
  172. if [ $? -ne 0 ]; then
  173.     if [ -f /proc/pci ]; then
  174.         grep -A 4 USB /proc/pci | grep memory > /dev/null
  175.         if [ $? -eq 0 ]; then
  176.         # ok, we have a OHCI controller, check if the linux driver is loaded
  177.             grep "^S:  Product=USB OHCI Root Hub" /proc/bus/usb/devices > /dev/null
  178.             if [ $? -ne 0 ]; then
  179.                 echo "OHCI support is missing... trying to load" ;
  180.                 modprobe usb-ohci
  181.                 sleep 2
  182.                 grep "^S:  Product=USB OHCI Root Hub" /proc/bus/usb/devices > /dev/null
  183.                 if [ $? -ne 0 ]; then
  184.                     echo "OHCI support: failed to load" ;
  185.                 else
  186.                     echo "OHCI support is OK" ;
  187.                     ohci=1 ;
  188.                 fi
  189.             else
  190.                 echo "OHCI support is OK" ;
  191.                 ohci=1 ;
  192.             fi
  193.         fi
  194.     else
  195.         echo "You don't have /proc/pci. I cannot check for a OHCI controller";
  196.     fi
  197. else
  198.     echo "OHCI support is OK" ;
  199.     ohci=1;
  200. fi
  201.  
  202. if [ $uhci -eq 0 -a $ohci -eq 0 ]; then
  203.     echo "I found no USB controller" ;
  204.     fatal;
  205. fi
  206.  
  207. # check for the presense of /dev/ppp
  208. if [ ! -c /dev/ppp ]; then
  209.     echo "/dev/ppp is missing... trying to create" ;
  210.     mknod /dev/ppp c 108 0
  211.     if [ ! -c /dev/ppp ]; then
  212.         echo "/dev/ppp: failed to create" ;
  213.         fatal;
  214.     fi
  215. fi
  216.  
  217. # check some property of /dev/ppp
  218. set `ls -la /dev/ppp`
  219. if [ $3 != "root" ]; then
  220.     echo "/dev/ppp should be owned by root... trying to change" ;
  221.     chown root /dev/ppp
  222.     set `ls -la /dev/ppp`
  223.     if [ $3 != "root" ]; then
  224.         echo "/dev/ppp: failed to change owner to root" ;
  225.         fatal;
  226.     fi
  227. fi
  228.  
  229. if [ $5 != "108," ]; then
  230.     echo "/dev/ppp has a bad major number... trying to change" ;
  231.     rm /dev/ppp
  232.     mknod /dev/ppp c 108 0
  233.     set `ls -la /dev/ppp`
  234.     if [ $5 != "108," ]; then
  235.         echo "/dev/ppp: failed to change major number" ;
  236.         fatal;
  237.     fi
  238. fi
  239.  
  240. if [ $6 != "0" ]; then
  241.     echo "/dev/ppp has a bad minor number... trying to change" ;
  242.     rm /dev/ppp
  243.     mknod /dev/ppp c 108 0
  244.     set `ls -la /dev/ppp`
  245.     if [ $6 != "0" ]; then
  246.         echo "/dev/ppp: failed to change minor number" ;
  247.         fatal;
  248.     fi
  249. fi
  250. echo "/dev/ppp is OK" ;
  251.  
  252. # check for the HDLC support
  253. "$BIN_DIR/check-hdlc"
  254. if [ $? -ne 0 ]; then
  255.     echo "HDLC support is missing... trying to load" ;
  256.     modprobe n_hdlc ;
  257.     ./check-hdlc ;
  258.     if [ $? -ne 0 ]; then
  259.         echo "HDLC support: failed to load" ;
  260.         echo "You should check your kernel config with: cd /usr/src/linux ; make menuconfig" ;
  261.         echo "and look under Character devices for Non-standard serial port support and" ;
  262.         echo "HDLC line discipline support" ;
  263.         fatal;
  264.     fi
  265. # here, HDLC support is OK, but maybe some alias are missing
  266.     modprobe -r n_hdlc ;
  267.     ./check-hdlc ;
  268.     if [ $? -ne 0 ]; then
  269.         echo "HDLC support: alias is missing... trying to add" ;
  270.         echo "alias tty-ldisc-13 n_hdlc" >> "$ETC_DIR/modules.conf" ;
  271.         depmod -a ;
  272. # checking again
  273.         ./check-hdlc ;
  274.         if [ $? -ne 0 ]; then
  275.             echo "HDLC support: adding alias does not work" ;
  276.             fatal;
  277.         else
  278.             echo "HDLC support is OK" ;
  279.         fi
  280.     else
  281.         echo "HDLC support is OK" ;
  282.     fi
  283. else
  284.     echo "HDLC support is OK" ;
  285. fi
  286.  
  287. # check for the HDLC bug
  288. "$BIN_DIR/check-hdlc-bug" > /dev/null 2>&1
  289. if [ $? -ne 0 ]; then
  290.     echo "HDLC support is buggy, you should apply the HDLC patch to your \
  291. kernel source. See the howto in the doc directory or on \
  292. http://eciadsl.sourceforge.net/ in the Documentation section for further \
  293. instructions." ;
  294. else
  295.     echo "HDLC support is OK (no bug)" ;
  296. fi
  297.  
  298. if [ -s "$CONF_DIR/eciadsl.conf" ]; then
  299.     vid1=`grep -E "^[ \t]*VID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  300.     pid1=`grep -E "^[ \t]*PID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  301.     vid2=`grep -E "^[ \t]*VID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  302.     pid2=`grep -E "^[ \t]*PID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  303.     eciload1_options=`grep -E "^[ \t]*ECILOAD1_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -s "\t" " "`
  304.     eciload2_options=`grep -E "^[ \t]*ECILOAD2_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -s "\t" " "`
  305. else
  306.     echo -e "\ncouldn't find $CONF_DIR/eciadsl.conf, default config assumed"
  307. fi
  308. test -z "$vid1" && vid1="0547"
  309. test -z "$pid1" && pid1="2131"
  310. test -z "$vid2" && vid2="0915"
  311. test -z "$pid2" && pid2="8000"
  312.  
  313. # check for the EZUSB chip
  314. ezusb=0
  315. grep "^P:  Vendor=$vid1 ProdID=$pid1" /proc/bus/usb/devices > /dev/null
  316. if [ $? -eq 0 ]; then
  317.     ezusb=1 ;
  318.     echo "Loading EZ-USB firmware... ";
  319.     $BIN_DIR/eci-load1 $eciload1_options
  320.     if [ $? -ne 0 ] ; then
  321.         echo "Failed to load EZ-USB firmware" ;
  322.         fatal ;
  323.     fi ;
  324.     echo "Loading the GlobeSpan firmware..." ;
  325.     $BIN_DIR/eci-load2 $eciload2_options
  326.     if [ $? -ne 0 ] ; then
  327.         echo "Failed to load GlobeSpan firmware" ;
  328.         fatal ;
  329.     fi ;
  330. fi
  331.  
  332. # check for the $PPPD_DIR/peers/adsl file (if the user is using another name,
  333. # he knows what he's doing and does not need this script).
  334.  
  335. if [ ! -f $PPPD_DIR/peers/adsl ]; then
  336.     echo "No $PPPD_DIR/peers/adsl: did you install the ECI driver?" ;
  337.     fatal;
  338. fi
  339.  
  340. # Note: user option (either in $PPPD_DIR/peers/adsl or $PPPD_DIR/chap-secrets)
  341. # can be :
  342. # user TheUser
  343. # user "TheUser"
  344. # user 'TheUser'
  345.  
  346. # check for an existing user param. The actual user param may be
  347. # within "" or not.
  348. user=`grep "^user" $PPPD_DIR/peers/adsl | awk '{print $2}'`
  349. if [ "$user" = "" ]; then
  350.     echo "Option 'user' if missing from $PPPD_DIR/peers/adsl: Fatal" ;
  351.     fatal ;
  352. fi
  353.  
  354. # remove "" and '' from $user if needed.
  355. n=`echo $user | cut -d'"' -f2` ;
  356. if [ "$n" != "" ]; then
  357.     user=$n;
  358. fi
  359. n=`echo $user | cut -d'"' -f2`;
  360. if [ "$n" != "" ]; then
  361.     user=$n;
  362. fi
  363.  
  364. # check that the user param is the same is $PPPD_DIR/peers/adsl and
  365. # $PPPD_DIR/chap-secrets
  366.  
  367. grep "^$user[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
  368. if [ $? -ne 0 ]; then
  369.     grep "^'$user'[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
  370.     if [ $? -ne 0 ]; then
  371.         grep "^\"$user\"[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
  372.         if [ $? -ne 0 ]; then
  373.             echo "$PPPD_DIR/chap-secrets: no password for $user" ;
  374.             echo "Give me the password for $user:"
  375.             read pwd
  376.             echo "$user * $pwd *" >> $PPPD_DIR/chap-secrets
  377.         fi
  378.     fi
  379. else
  380.     echo "$PPPD_DIR/chap-secrets is OK" ;
  381. fi
  382.  
  383. # check for the Globespan chip
  384. grep "^P:  Vendor=$vid2 ProdID=$pid2" /proc/bus/usb/devices > /dev/null
  385. if [ $? -ne 0 ]; then
  386.     echo "I cannot find your ADSL modem: Fatal"
  387.     fatal;
  388. fi
  389.  
  390. # check for an existing pppd
  391. x=`which pppd`
  392. if [ "$x" = "" ]; then
  393.     echo "No pppd is intalled: Fatal" ;
  394.     exit -1;
  395. fi
  396.  
  397. # check the pppd version
  398. ppp_version=`pppd --version | cut -d" " -f 3` ;
  399. msg="";
  400. if [ "$ppp_version" != "2.4.0" -a "$ppp_version" != "2.4.1" ]; then
  401.     msg=" (untested)" ;
  402. fi
  403. echo "You are using pppd version $ppp_version$msg" ;
  404.  
  405. # check for an existing $PPPD_DIR/options file
  406. if [ -f $PPPD_DIR/options ]; then
  407.     echo "You have an $PPPD_DIR/options file. Options in this file may conflict with" ;
  408.     echo "options from $PPPD_DIR/peers/adsl. We suggest to remove this file or make a";
  409.     echo "backup copy." ;
  410.     grep "^nodetach" $PPPD_DIR/options > /dev/null
  411.     if [ $? -eq 0 ]; then
  412.         echo "Removing 'nodetach' option from $PPPD_DIR/options..." ;
  413.         grep -v "^nodetach" $PPPD_DIR/options > /tmp/options
  414.         mv /tmp/options $PPPD_DIR/options
  415.     fi
  416. fi
  417.  
  418. # check for an existing PPP connection (select the first one if several)
  419. PPP=`ifconfig | grep "^ppp" | head -1 | awk '{print $1}'`
  420. if [ "$PPP" = "" ]; then
  421.     echo "No existing PPP connection... trying to make one (please wait)" ;
  422.     nice --20 pppd call adsl updetach | tee /tmp/ppp.log
  423.  
  424. # check if we succeed in making a new PPP connection
  425.     PPP=`ifconfig | grep "^ppp" | head -1 | awk '{print $1}'`
  426.     if [ "$PPP" = "" ]; then
  427.         # check for usermode driver crash
  428.         grep "Modem hangup" /tmp/ppp.log > /dev/null
  429.         if [ $? -eq 0 ]; then
  430.             echo "PPP: very bad ... usermode driver just crashed" ;
  431.             rm /tmp/ppp.log
  432.             fatal;
  433.         fi
  434.         # check for no response from PPP
  435.         grep 'LCP: timeout sending Config-Requests' /tmp/ppp.log > /dev/null
  436.         if [ $? -eq 0 ]; then
  437.             echo "PPP connection failed: check your vci & vpi parameters in $PPPD_DIR/peers/adsl and check for USB errors in /var/log/messages" ;
  438.             rm /tmp/ppp.log
  439.             fatal;
  440.         fi
  441.         # check for invalid password
  442.         grep 'CHAP authentication failed' /tmp/ppp.log > /dev/null
  443.         if [ $? -eq 0 ]; then
  444.             echo "CHAP authentication failed: check your user in $PPPD_DIR/peers/adsl and the matching password in $PPPD_DIR/chap-secrets" ;
  445.             rm /tmp/ppp.log
  446.             fatal;
  447.         fi
  448.         # check for "sent [LCP ConfRej id=0xa5 <auth chap MD5>]"
  449.         grep 'sent \[LCP ConfRej' /tmp/ppp.log | grep '<auth chap MD5>' > /dev/null
  450.         if [ $? -eq 0 ]; then
  451.             echo "Password for user $user is missing in $PPPD_DIR/chap-secrets";
  452.             rm /tmp/ppp.log
  453.             fatal;
  454.         fi
  455.         echo "Cannot make a PPP connection: Fatal" ;
  456.         rm /tmp/ppp.log
  457.         fatal;
  458.     else
  459.         rm /tmp/ppp.log
  460.         echo "PPP connection is OK" ;
  461.     fi
  462. else
  463.     echo "PPP connection is OK" ;
  464. fi
  465.  
  466. # check for the default route over pppN
  467. route -n | grep "^0.0.0.0" | grep $PPP > /dev/null
  468. if [ $? -ne 0 ]; then
  469.     echo "No default route over $PPP... trying to add" ;
  470.     route add default dev $PPP
  471.     route -n | grep "^0.0.0.0" | grep $PPP > /dev/null
  472.     if [ $? -ne 0 ]; then
  473.         echo "No default over $PPP: failed" ;
  474.         fatal;
  475.     else
  476.         echo "Default route over $PPP is OK" ;
  477.     fi
  478. else
  479.     echo "Default route over $PPP is OK" ;
  480. fi
  481.  
  482. # check for the default route not over ethN
  483. route -n | grep "^0.0.0.0" | grep -v $PPP > /dev/null
  484. if [ $? -eq 0 ]; then
  485.     echo "You have default route(s) not over $PPP... trying to delete" ;
  486.     other=`route -n | grep "^0.0.0.0" | grep -v $PPP | awk '{print $8}'`;
  487.     for itf in $other;
  488.     do
  489.         echo "Deleting default route over $itf" ;
  490.         route del default dev $itf ;
  491.     done
  492.     route -n | grep "^0.0.0.0" | grep -v $PPP > /dev/null
  493.     if [ $? -eq 0 ]; then
  494.         echo "Deleting default route not over $PPP: failed" ;
  495.         fatal;
  496.     fi
  497. fi
  498.  
  499. # check if ICMP packets are sent & received (is it usefull?)
  500. #ping -c 10 yahoo.fr > /dev/null
  501. #if [ $? -eq 0 ]; then
  502. #    echo "ICMP traffic is OK" ;
  503. #else
  504. #    echo "ICMP traffic does not work" ;
  505. #fi
  506.  
  507. # check for /var/log or /tmp partitions full (TODO)
  508. # check for "rcvd [LCP TermReq id=0xa8]" (TODO)
  509. # check for $ETC_DIR/resolv.conf validity (TODO)
  510. # check for an already running pppd & pppoeci, while no ppp0 (TODO)
  511. # check for $PPPD_DIR/pap-secrets too (TODO)
  512. # check for either pap-secrets or chap-secrets, how? (TODO)
  513.  
  514. echo "Everything is OK"
  515.